<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span @click="deleteAllSearchHistories">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow = false">完成</span>
      </div>
      <van-icon v-else name="delete" @click="isDeleteShow = true"/>
    </van-cell>
    <van-cell v-for="(history,index) in searchHistories" :key="index" :title="history">
      <van-icon v-show="isDeleteShow" name="close" @click="onDelete(history, index)"/>
    </van-cell>
  </div>
</template>

<script>
import { mapState } from 'Vuex'
// import { setItem } from '@/utils/storage.js'
export default {
  name: 'SearchHistory',
  props: {
    searchHistories: {
      type: Array,
      required: true
    }
  },
  components: {},
  data () {
    return {
      isDeleteShow: false
    }
  },
  computed: {
    ...mapState({
      user: state => state.user.user
    })
  },
  watch: {},
  methods: {
    onDelete (history, index) {
      if (!this.isDeleteShow) {
        this.$emit('search', history)
      } else {
        this.searchHistories.splice(index, 1)
      }
    },
    deleteAllSearchHistories () {
      this.$emit('update-search-histories', [])
    }
  },
  created () {
  },
  mounted () {
  },
  destroyed () {
  }
}
</script>

<style scoped lang='less'>
</style>
